/*
 * StudentFatherDb.cpp
 *
 *  Created on: 26 Apr 2010
 *      Author: Vastsor
 */

#include "StudentFatherDb.h"
StudentFatherDb::StudentFatherDb() {

}

StudentFatherDb::StudentFatherDb(const string *dbName, const string *user, const string *passwd) {
	OdbcConnectionSingleton::getInstance()->connect(dbName,user,passwd);

}
bool
StudentFatherDb::saveFather(const string *afm, const string *name, const string *lastName, const string *occupation) const {
	bool ret=false;
	SQLHANDLE stmtHandle = OdbcConnectionSingleton::getInstance()->getStmtHandle();
	SQLRETURN rc;

	string sqlString="INSERT INTO StudentFathers (afm,name,lastName,occupation) VALUES('"+*afm+"'";
	sqlString+=",'"+*name+"','"+*lastName+"','"+*occupation+"')";

	rc = SQLExecDirect(stmtHandle,(SQLTCHAR *)sqlString.c_str(),SQL_NTS);
	if( rc == SQL_SUCCESS) {
		ret=true;
	}
return ret;
}

StudentFatherDb::~StudentFatherDb() {
	// TODO Auto-generated destructor stub
}



bool StudentFatherDb::saveStudentFather(const string *afm, const string *aem) const {
	bool returnValue=false;
	SQLRETURN rc;
	SQLHANDLE stmtHandle=OdbcConnectionSingleton::getInstance()->getStmtHandle();

	string sqlString="UPDATE Students set StudentF_afm='"+*afm+"' where aem='"+*aem+"'";
		rc = SQLExecDirect(stmtHandle, (SQLTCHAR *)sqlString.c_str(), SQL_NTS);
		if(rc==SQL_SUCCESS){
				returnValue=true;
				}

return returnValue;
}

bool
StudentFatherDb::isFind(const string *afm) const {
	bool returnValue=false;
	SQLRETURN rc;
	SQLHANDLE stmtHandle=OdbcConnectionSingleton::getInstance()->getStmtHandle();
	char cAfm[255];
	string sqlString="SELECT afm From StudentFathers where afm='"+*afm+"'";
	rc = SQLExecDirect(stmtHandle, (SQLTCHAR *)sqlString.c_str(), SQL_NTS);
	if(rc==SQL_SUCCESS){
		SQLBindCol(stmtHandle,1,SQL_C_CHAR,cAfm,sizeof(cAfm),NULL);
		if((rc  = SQLFetch(stmtHandle))!= SQL_NO_DATA) {
					returnValue=true;
					}
	}
return returnValue;
}

